<template>
  <el-cascader v-model="selectValue" :value="value" size="mini" :options="detailOptions" :props="prop" separator="-" @change="changeInput" />
</template>

<script>
import { getDepartmentList } from '@/api/department'
import { transListToTreeData } from '@/utils/index'
export default {
  name: 'SelectTree',
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      selectValue: '',
      detailOptions: [],
      prop: {
        label: 'name',
        value: 'id'
      }
    }
  },
  created() {
    this.getDepartmentList()
  },
  methods: {
    async getDepartmentList() {
      this.detailOptions = transListToTreeData(await getDepartmentList(), 0)
    },
    changeInput(data) {
      if (data.length) {
        this.$emit('input', data[data.length - 1])
      } else {
        this.$emit('input', null)
      }
    }
  }
}
</script>

<style>

</style>
